{include file='header.html'}
        <link type="text/css" href="../../page/css/reset.css" rev="stylesheet" rel="stylesheet">
        <link type="text/css" href="../../page/css/chuchai.css" rev="stylesheet" rel="stylesheet">
        <link type="text/css" href="{$common_domain}/tools/datepicker/jquery.ui.theme.css" rel="stylesheet" />
        <link type="text/css" href="{$common_domain}/tools/datepicker/jquery.ui.datepicker.css" rel="stylesheet" />
        <link type="text/css" href="{$common_domain}/tools/datepicker/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
        <script type="text/javascript" src="{$common_domain}/tools/datepicker/jquery-1.7.2.js"></script>
        <script type="text/javascript" src="{$common_domain}/tools/datepicker/jquery.ui.core.js"></script>
        <script type="text/javascript" src="{$common_domain}/tools/datepicker/jquery.ui.widget.js"></script>
        <script type="text/javascript" src="{$common_domain}/tools/datepicker/jquery.ui.datepicker.js"></script>
        <script type="text/javascript" src="{$common_domain}/tools/datepicker/DateTimePicker.js"></script>
        <script type="text/javascript">
        $(document).ready(function(){
            bindListener();
          }
        )
        var i = 0;
        //新增出差流程表单
        function addform(){
            var form = '';
            form +='<div class="spanner">';
            form += '<ul class="li_ul">';
            form += '<li style="width:147px;"><input readonly="readonly" name="detail_trip_date[]" type="text" size="16" id="detail_trip_date_'+i+'" class="jko1" value=""/></li>';
            form += '<li><input name="detail_trip_original[]" class="jocgp" name="trip_original" type="text" size="10"/></li>';
            form += '<li><input name="detail_trip_destingation[]" class="jocgp" name="trip_destinguation" type="text" size="10"/></li>';
            form += '<li style="width:77px;"><select name="detail_trip_method[]" style="" id="tool'+i+'" onchange="getValue('+i+')"><option>请选择</option><option value="飞机">飞机</option><option value="汽车">汽车</option><option value="火车">火车</option></select></li>';
            form += '<li style="width:105px;"><select name="detail_trip_start_time[]" style="width:105px" id="time'+i+'"></select></li>';
            form += '<li style="width:120px;"><select style="width:80px" name="detail_trip_hotel[]" type="text" id="dayNum'+i+'" /></select><a href="javascript:void(0)" name="rmlink" class="xich_te_c">删除</a></li>';
            form += '</ul><div class="clear"></div>';
            form += '</div>';
            $("#trip_details").append(form);
            $("#detail_trip_date_"+i).unbind().datetimepicker();
            bindListener();
            addDay(i);
            i++;
        }
        function bindListener(){
          $("a[name=rmlink]").unbind().click(function(){
            $(this).parent().parent().parent().remove();
          }
          )
        }
        $(function () {
            var startTime;
            $("#detail_trip_date").datetimepicker();
            $("#start_time_id").datetimepicker({ minDate: 3});
           $("#end_time").datetimepicker();




            addDay('');
        });
        //表单完整性验证
        function check_submit(){
            //如果是上传图片使用
            var is_up_file = $('#is_up_file').val();
            if(is_up_file == '1'){
                $('#frmAsk').submit();
                return true;
            }
            if($('input:radio[name="leave_reason"]:checked').val()==null){
                alert('请选择出差事由');
                return false;
            }
            if($('input:radio[name="leave_reason"]:checked').val() =='其他'){
                if($('#o_l_reason').val()==''){
                    alert('请填写出差事由');
                    return false;
                }
            }
            if($('#start_time_id').val() =='' || $('#end_time').val()==''){
                alert('出差日期不能为空');
                return false;
            }
            $('#frmAsk').submit();
        }
            var url = "{$base_url}/askleave/";
            $.datetimepicker.after_set = function($this){
                var id = $this.attr("id");
                //提前3天
                var start = $("#start_time_id").val();
                var end = $("#end_time").val();
                if( start == ''){
                    $("#"+id).val("");
                    alert('请选择出差“开始”时间');
                    return ;
                }
                if(id == 'start_time_id'){
                    $("#end_time").datepicker("option","minDate",start.split(' ')[0]);
                }
                if(id == 'start_time_id'|| id == 'end_time'){
                    var start_date = get_date(start);
                    var now_date = new Date();
                    now_date.setDate(now_date.getDate()+3);
                    now_date.setMonth(now_date.getMonth()+1);
                    if(now_date.getTime() > start_date.getTime()){
                        $("#"+id).val("");
                        alert('请提前3天申请');
                        return ;
                    }
                }
                if(id == 'end_time'){
                    if( end == ''){
                        $("#"+id).val("");
                        alert('请选择出差“结束”时间');
                        return;
                    }
                    var end_date = get_date(end);
                    if(start_date.getTime()>end_date.getTime()){
                        //$("#"+id).val("");
                        //alert('开始时间应大于结束时间');
                        //return;
                    }
                }
                if( id == 'start_time_id' || id == 'end_time' ) {
                     var start = $("#start_time_id").val();
                     var end = $("#end_time").val();
                     if( start == '' || end == ''){
                         return ;
                     }else{
                        //if(comptime(start,end)){
                            $.post(url,{ start:start,end:end,type:'出差',cal:'long'},function (data) {
                                if(data.is_ever == 1){
                                    $("#days").val(0);
                                    $("#"+id).val("");
                                    alert("您在"+data.start_time+"至"+data.end_time+"已经申请了"+data.type);
                                }else{
                                    $("#days").val(data.day);
                                }
                            },'json');
                        //}else{
                              //alert("结束时间不能小于开始时间");
                              //$("#"+id).val("");
                        // }
                     }
                     $('input[name="detail_trip_date[]"]').each(function(){
                          $(this).val("");
                     });
               }else if(id.substr(0,'detail_trip_date'.length)=='detail_trip_date'){
                   var detail_trip_date = $("#"+id).val();
                   if(detail_trip_date == ''){
                       return ;
                   }
                   if(!in_start_end(start,end,detail_trip_date)){
                       //alert('行程时间应在出差时间内！');
                       //$("#"+id).val("");
                   }
               }
            }
            function comptime(startDate,endDate) {
                //end >= start
                   if (get_time(startDate) >= get_time(endDate)) {
                      return false;
                   } else {
                      return true;
                   }
            }
            function in_start_end(startDate,endDate,middleTime){
                if(get_time(middleTime) >= get_time(startDate) && get_time(endDate) >= get_time(middleTime)){
                    return true;
                }else{
                    return false;
                }
            }
            function get_time(datetime){
                datetime =datetime+":00";
                var startDateTemp = datetime.split(" ");
                var arrStartDate = startDateTemp[0].split("-");
                var arrStartTime = startDateTemp[1].split(":");
                var allStartDate = new Date(arrStartDate[0], arrStartDate[1], arrStartDate[2], arrStartTime[0], arrStartTime[1], arrStartTime[2]);
                return allStartDate.getTime();
            }
            function get_date(datetime){
                datetime =datetime+":00";
                var startDateTemp = datetime.split(" ");
                var arrStartDate = startDateTemp[0].split("-");
                var arrStartTime = startDateTemp[1].split(":");
                var allStartDate = new Date(arrStartDate[0], arrStartDate[1], arrStartDate[2], 23, 59, 59);
               return allStartDate;
            }
            function getValue(ii){
                var tool = $("#tool"+ii).val();
                addHtml(tool,ii);
            }
            function addHtml(v,ii){
                var add = $("#time"+ii);
                $("#time"+ii).html("");
                if(v !=''){
                    for(var i= 0;i<24;i++){
                        var option = $("<option value="+i+">"+v+" "+i+":00</option>")
                        add.append(option);
                    }
                }
            }
            function addDay(ii){
                var addDay = $("#dayNum"+ii);
                for(var i= 0;i<11;i++){
                    if(i==0){
                        var option = $("<option>请选择</option>");
                    }
                    else{
                        var option = $("<option value="+i+"> "+i+"天</option>");
                        }
                    addDay.append(option);
                }
            }
            var KQUpload = {
                    checkFileExt: function(filename){
                           var allow_ext = new  Array('.jpg','.jpeg','.gif');
                           var ext = filename.substr(filename.lastIndexOf(".")).toLowerCase();
                           if(allow_ext.indexOf(ext) != -1){  return true; }
                           return false;
                        },
                    upload_img: function(){
                        $("#frmAsk").attr("action", "/ajaxupload/");
                        $("#frmAsk").attr("target",'upload_frame');
                        $("#frmAsk").submit();
                        $("#frmAsk").attr("action", "");
                        $("#frmAsk").attr("target",'');
                    },
                    del_img:function(){
                        $('#need_img_li').hide();
                        $('#need_img').attr('src','');
                        $('#need_img_a').attr('href','');
                        $('#img_file').val('');
                        $('#is_up_file').val(0);
                    }
                };
                $(document).ready(function(){
                    $('#photo_up').change(function(){
                        if(!KQUpload.checkFileExt(this.value)){
                            alert('您上传的图片类型不符合规则！请重新上传');
                            return false;
                         }else{
                             $('#is_up_file').val(1);
                             KQUpload.upload_img();
                         }
                    });
                });
        </script>
            <div id="content">
                <i class="con_l">&nbsp;</i>
                <i class="con_r">&nbsp;</i>
                <div class="main">
                    <div class="blank"></div>

                    <form id="frmAsk" action="" method="post" enctype="multipart/form-data">
                    <ul class="ul_cc">
                    <li class="s radio1">
                        <b class="li_b">出差事由</b>
                        <div class="sp1">
                            <input value="考察市场" type="radio" name="leave_reason" {if $post_data['leave_reason']=='考察市场'}checked="checked"{/if} />
                            考察市场
                            <input value="筹建分公司" type="radio" name="leave_reason" {if $post_data['leave_reason']=='筹建分公司'}checked="checked"{/if} />
                            筹建分公司
                            <input value="市场活动" type="radio" name="leave_reason" {if $post_data['leave_reason']=='市场活动'}checked="checked"{/if} />
                            市场活动
                            <input value="培训" type="radio" name="leave_reason" {if $post_data['leave_reason']=='培训'}checked="checked"{/if} />
                            培训
                            <input value="工作指导" type="radio" name="leave_reason" {if $post_data['leave_reason']=='工作指导'}checked="checked"{/if} />
                            工作指导
                            <input value="其他" type="radio" name="leave_reason" {if $post_data['leave_reason']=='其他'}checked="checked"{/if} />
                            其他
                            <input id="o_l_reason" name = "other_leave_reason" type="text" size="10" style="border: 1px solid #ddd;"/>
                        </div>
                    </li>
                    <li class="s xingch">
                        <b class="li_b">日期</b>
                        <input readonly="readonly" id="start_time_id" name="start_time" type="text" value="{$org_info.start_time}"  class="jko1" />
                        至
                        <input readonly="readonly" id="end_time" name="end_time" type="text" value="{$org_info.end_time}" class="jko1" /><span class="tach" id = "tach" style=""><span class="ic"></span><span id="tach_text" style="font-weight:bold; ">出差请提前3天申请！</span><span class="ico"><a href="/help/" target="_blank" title="查看帮助文档">&nbsp;</a></span></span>{if $error_msg.start_time or $error_msg.end_time}<span class="error_msg">Note:{$error_msg.start_time}&nbsp;&nbsp;{$error_msg.end_time}</span>{/if}
                        {if $error_msg.time_error}<span class="error_msg">{$error_msg.time_error}</span>{/if}
                    </li>
                    <li class="s xingch">
                        <b class="li_b">出差行程</b>
                        <ul class="li_ul">
                           <li style="width:147px;">
                                <b class="li_b">日期</b>
                            </li>
                            <li>
                                <b class="li_b">出发地</b>
                            </li>
                            <li>
                                <b class="li_b">目的地</b>
                            </li>
                            <li style="width:190px;">
                                <b class="li_b">交通工具</b>
                            </li>
                            <li style="width:208px">
                                <b class="li_b">住宿天数</b>
                            </li>
                        </ul>
                        <div class="clear"></div>
                        <div class="spanner">
                        <ul class="li_ul">
                            <li style="width:147px;">
                                <input readonly="readonly" id="detail_trip_date" value="{$org_info.detail_trip_date.0}"  name="detail_trip_date[]" type="text" size="16" class="jko1" value="" />
                            </li>
                            <li>
                                <input class="jocgp" value="{$org_info.detail_trip_original.0}" name="detail_trip_original[]" type="text" size="10"/>
                            </li>
                            <li>
                                <input class="jocgp" value="{$org_info.detail_trip_destingation.0}" name="detail_trip_destingation[]" type="text" size="10"/>
                            </li>
                            <li style="width:77px;">
                                <select name="detail_trip_method[]" style="" id="tool" onchange="getValue('')">
                                    <option value=''>请选择</option>
                                    <option value='飞机'>飞机</option>
                                    <option value='汽车'>汽车</option>
                                    <option value='火车'>火车</option>
                                </select>
                            </li>
                            <li style="width:105px;">
                                <select name="detail_trip_start_time[]" style="width:105px" id="time">
                                </select>
                            </li>
                            <li style="width:80px">
                                <select style="width:80px" value="{$org_info.detail_trip_hotel.0}" name="detail_trip_hotel[]" type="text" id="dayNum" /></select>
                            </li>
                            {if $error_msg.trip_details}<li style="width:250px;line-height: 28px;" class="error_msg">{$error_msg.trip_details}</li>{/if}
                        </ul>
                        <div class="clear"></div>
                        </div>
                        <div id="trip_details">
                        </div>

                    </li>
                    <li class="s">
                        <a href="javascript:addform();" class="xich_te_c">+ 添加行程</a>
                    </li>
                    <li class="s">
                        <b class="li_b">天数</b>
                        <input id="days" readonly="readonly"  name="leave_time" type="text" value="{$org_info.leave_time}" size="10" class="inp"/>&nbsp;天{if $error_msg.leave_time}<span class="error_msg"></span>{/if}
                    </li>
                    <li class="s">
                        <b class="li_b">图片(文件大小<2M,支持格式jpg/gif)</b>
                        <a id="" href="javascript:;" class="tian_one_span">
                          上传证明
                          <input id="photo_up" class="vis2op" type="file" hidefocus="hidefocus" name="file">
                      </a>{if $error_msg.file_error}<span class="error_msg">{$error_msg.file_error}</span>{/if}
                    </li>
                    <li class="s" style="display:none" id="need_img_li">
            <input type="hidden" name="is_up_file" id="is_up_file" value="0">
            <input type="hidden" name="img_file" id="img_file" value="">
            <a href="" target="_blank" id="need_img_a" title="点击查看大图"><img id="need_img" width="240" height="180"></a>&nbsp;<a href="javascript:void(0);" onclick="KQUpload.del_img()" style="margin:0 0 0 10px;">删除</a>
            </li>
                    <li class="s shenpi" >
                        <b>审批人:{$dtp_info.name}</b>
                    </li>
                    <li class="s">
                        <b class="li_b">Note:</b>
                        <textarea name="note" cols="100" rows="3" id="tre">{$org_info.note}</textarea>{if $error_msg.note}<span class="error_msg">{$error_msg.note}</span>{/if}
                    </li>
                    <li class="s">
                        <button onclick="check_submit()" type="button" class="lgo">提交申请</button>
                    </li>
                </ul>
</form>

                </div>
            </div>
        </div>
<iframe name="upload_frame" id="upload_frame" style="width:0;height:0;display:none;" ></iframe>
{include file='footer.html'}
